#include "MenuLogic.h"

#include "../Graphic/Graphic.h"
#include "../World/World.h"

int Menu_Show = 0;
int Menu[24];
int MenuLogic_ID = 0;

int MenuLogic_BuildID(char *Title)
{
    int ID = TILE_EMPTY;

    if(strcmp(Title, "house1") == 0)
        ID = TILE_HOUSE;
    else if(strcmp(Title, "house2") == 0)
        ID = TILE_HOUSE2;
    else if(strcmp(Title, "woodcutter") == 0)
        ID = TILE_WOODCUTTER;
    else if(strcmp(Title, "warehouse") == 0)
        ID = TILE_WAREHOUSE;
    else if(strcmp(Title, "encampment") == 0)
        ID = TILE_ENCAMPMENT;
    else if(strcmp(Title, "stonework") == 0)
        ID = TILE_STONEWORK;
    else if(strcmp(Title, "road") == 0)
        ID = TILE_ROAD;
    else if(strcmp(Title, "icon_build") == 0)
        ID = TILE_ICON_BUILD;

    return ID;
}

void MenuLogic_Build(int i, char *Title)
{
    int ID = MenuLogic_BuildID(Title);

    /* Eintrag bearbeiten */
    switch(ID) {
        case TILE_ICON_BUILD:
            if(!Menu_Show) {
                /* Menü erstellen */
                MenuLogic_BuildCreate();
                return;
            }
            else {
                /* Menü löschen */
                MenuLogic_BuildDelete();
                return;
            }
        break;
        default:
        break;
    }

    /* Setzten */
    MenuLogic_ID = ID;

    /* Menü löschen */
    MenuLogic_BuildDelete();
    return;
}

void MenuLogic_BuildDelete()
{
    int i;

    /* Einzeln löschen */
    for(i = 0; i < Menu_Show; i++) {
        Menu_Remove(Menu[i]);
    }

    /* Zurücksetzen */
    Menu_Show = 0;
}

void MenuLogic_BuildCreate()
{
    int i = 0;
    int X = 50;
    int Y = 120;
    Menu[i++]=Menu_Create( X, Y+(i*60), "road", &Graphic_BuildIcon, &MenuLogic_Build);
    Menu[i++]=Menu_Create( X, Y+(i*60), "house1", &Graphic_BuildIcon, &MenuLogic_Build);
    Menu[i++]=Menu_Create( X, Y+(i*60), "warehouse", &Graphic_BuildIcon, &MenuLogic_Build);
    Menu[i++]=Menu_Create( X, Y+(i*60), "encampment", &Graphic_BuildIcon, &MenuLogic_Build);
    Menu[i++]=Menu_Create( X, Y+(i*60), "stonework", &Graphic_BuildIcon, &MenuLogic_Build);
    Menu[i++]=Menu_Create( X, Y+(i*60), "woodcutter", &Graphic_BuildIcon, &MenuLogic_Build);

    /* Zahl merken*/
    Menu_Show = i;
}
